
<g:set var="firstPost" value="${thread.posts.first()}" />

<div class="forum-container">

    <ul class="thumbnails thread-first">

        <li class="thumbnail span11 thread-first">


            <div class="course-threads">

                <h5 class="name">
                    ${thread.name}
                    <small>
                        <g:message code="forum.createdby" />:  ${firstPost.user.firstname} ${firstPost.user.lastname}
                        <g:message code="forum.labels.on" /> <g:formatDate format="dd-MM-yyyy HH:mm" date="${thread.created}"/>
                    </small>
                </h5>

                <div class="thread-text">${firstPost.text}</div>

            </div>

        </li>

    </ul>

    <g:set var="tmp" value="${thread.posts.remove(firstPost)}" />

    <g:each in="${thread.posts}" var="post">

        <div class="thread-response span10">

            <div class="thread-text" id="post${post.id}-text">${post.text}</div>

            <g:if test="${post.user.id == session.user.id}">

                <div class="pull-left">

                    <a href="#modal-edit" class="edit-post" itemref="${post.id}" role="button" data-toggle="modal"><g:message code="default.button.edit.label" /></a>
                    |
                    <a href="Javascript:void(0)" class="delete-post" itemref="${post.id}" threadref="${thread.id}" itemconfirm="<g:message code="default.button.delete.confirm.message" />">
                        <g:message code="default.button.delete.label" />
                    </a>

                </div>

            </g:if>

            <div class="pull-right">

                <g:message code="forum.postedby" />:
                <span class="thread-response-user">
                    ${post.user.firstname} ${post.user.lastname}  <g:message code="forum.labels.on" /> <g:formatDate format="dd-MM-yyyy HH:mm" date="${post.date}"/>
                </span>

            </div>


        </div>

    </g:each>

    <div class="clearfix" style="margin-bottom: 20px;"></div>

    <a href="#modal" role="button" class="btn btn-info" data-toggle="modal"><g:message code="forum.posts.new" /></a>

</div>

<div id="modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel"><g:message code="forum.posts.new" /></h3>
    </div>
    <div class="modal-body">

        <input class="display-none" type="text"  name="userId" id="userId" value="${session.user.id}"/>
        <input class="display-none" type="text"  name="threadId" id="threadId" value="${thread.id}"/>
        <textarea class="forum-textarea" id="new-textarea" rows="3"></textarea>

    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true"><g:message code="forum.labels.cancel" /></button>
        <button id="newPost" class="btn btn-primary"><g:message code="forum.posts.newaction" /></button>
    </div>
</div>

<div id="modal-edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel2"><g:message code="forum.posts.edit" /></h3>
    </div>
    <div class="modal-body">


        <input class="display-none" type="text"  name="postId" id="postId" value=""/>
        <textarea class="forum-textarea" id="edit-textarea" rows="3"></textarea>

    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true"><g:message code="forum.labels.cancel" /></button>
        <button id="editPost" class="btn btn-primary"><g:message code="default.button.edit.label" /></button>
    </div>
</div>